import React from 'react';
import Add from './add';
import '../index.less';

export default function(props) {
  const actionType = getActionType(props.location.pathname);

  // 通过路由正则判断当前是什么页面，返回actionType
  function getActionType(pathname) {
    if (props.actionType) {
      return props.actionType;
    }
    const pathRegAdd = /.+(?=\/add)/;
    const pathRegEdit = /.+(?=\/\w+\/edit)/;
    const pathRegDetail = /.+(?=\/\w+\/detail)/;
    if (pathname.match(pathRegAdd)) {
      return 'add';
    }
    if (pathname.match(pathRegEdit)) {
      return 'update';
    }
    if (pathname.match(pathRegDetail)) {
      return 'detail';
    }
    return '';
  }
  return (
    <div className='stretegy-content'>
      <Add {...props} actionType={actionType} />
    </div>
  );
}
